import Vue from 'vue'
import App from './App'
import 'common/stylus/index.styl'
import router from './router'
import VueLazyLoad from 'vue-lazyload'
import store from './store'
import querystring from 'querystring'
Vue.prototype.$qs = querystring;
import axios from 'axios';
/* eslint-disable no-unused-vars */
// import vConsole from 'vconsole'

import MetaInfo from 'vue-meta-info'

Vue.use(MetaInfo)

import {
  Button,
  Carousel,
  CarouselItem,
  Card,
  Pagination,
  Select,
  Option,
  Badge,
  Dialog
} from 'element-ui';
 Vue.use(Button)
 Vue.use(Carousel)
 Vue.use(CarouselItem)
 Vue.use(Card)
 Vue.use(Pagination)
 Vue.use(Select)
 Vue.use(Option)
 Vue.use(Badge)
 Vue.use(Dialog)

Vue.prototype.$onError = function (error) {
  let error_msg = '网络错误';
  let toastFlag = true;
  switch (error.errorCode) {
    case 401:
      error_msg = '请先登录';
      break;
    case 500:
      error_msg = '服务器错误';
      break;
    case 504:
      error_msg = '网络超时'
      break;
    case 20000:
      toastFlag = false;
      this.$router.push({path: '/'});
      break;
  }
  if(toastFlag){
    this.$Toast({
      message: error_msg,
      position: 'bottom',
      duration: 2000,
      callback: () => {
        this.$router.push({path: '/'});
      }
    })
  }
}

Vue.use(VueLazyLoad, {
  loading: require('common/image/default_gray.png')
})

axios.defaults.baseURL = process.env.BASE_API

Vue.prototype.$ajax = axios

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App),
  store
})
